//
//  Controller03.swift
//  Swift30Days
//
//  Created by licheng ke on 2017/2/27.
//  Copyright © 2017年 licheng ke. All rights reserved.
//

import UIKit

class Controller03: UIViewController,UITableViewDelegate,UITableViewDataSource,VideoCellDelegate {

    var data = [
        MyVideo(image: "videoScreenshot01", title: "Introduce 3DS Mario", source: "Youtube - 06:32"),
        MyVideo(image: "videoScreenshot02", title: "Emoji Among Us", source: "Vimeo - 3:34"),
        MyVideo(image: "videoScreenshot03", title: "Seals Documentary", source: "Vine - 00:06"),
        MyVideo(image: "videoScreenshot04", title: "Adventure Time", source: "Youtube - 02:39"),
        MyVideo(image: "videoScreenshot05", title: "Facebook HQ", source: "Facebook - 10:20"),
        MyVideo(image: "videoScreenshot06", title: "Lijiang Lugu Lake", source: "Allen - 20:30")
    ]
    
    var tableView : UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.black;
        configUI();
    }
    
    func configUI() {
        tableView = UITableView(frame:  UIScreen.main.bounds, style: .plain);
        tableView.dataSource = self;
        tableView.delegate = self;
        view.addSubview(tableView);
        tableView.register(UINib.init(nibName: "VideoCell", bundle: nil), forCellReuseIdentifier: "abc");
        tableView.tableFooterView = UIView();
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    //MARK: - delegate & dataSource
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 220;
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "abc", for: indexPath) as! VideoCell;
        cell.video = data[indexPath.row];
        cell.delegate = self;
        return cell;
    }
    
    func viewCellAction(_ myCell:VideoCell){
        print("cell title:\(myCell.video?.title)");
        //MARK: - playVideo need todo
    }

}
